package org.ohos.sample.cordova.util;


import com.ffsky.litepack.conf.AppConf;
import com.ffsky.litepack.logger.L;
import ohos.agp.components.webengine.WebConfig;
import ohos.agp.components.webengine.WebView;

public class WebSettingsCompat {

    public static final String USER_AGENT = "HarHybridJs/";

    public static void settings(WebView mWebView) {
        if(mWebView==null){
            return;
        }
        WebConfig webConfig = mWebView.getWebConfig();
        webConfig.setJavaScriptPermit(true);
        webConfig.setDataAbilityPermit(true);
        webConfig.setWebStoragePermit(true);
        webConfig.setViewPortFitScreen(true);
        webConfig.setUserAgent(setUserAgent(webConfig.getUserAgent()));

    }

    public  static String setUserAgent(String _ua) {
        StringBuffer buf = new StringBuffer();
        buf.append(_ua);
        buf.append(" ");
        buf.append(USER_AGENT);
        buf.append(AppConf.vName);
        buf.append("/");
        L.i("WebSettingsCompat", "setUserAgent-->", buf.toString());
        return buf.toString();
    }

}
